package com.geezdata.cps.base.statemachine;

import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.geezdata.cps.base.enums.ErrorCode;
import com.geezdata.cps.base.exceptions.MyException;

public abstract class AbstractStateMachine<S extends State<E>, E extends Stateable> implements StateMachine<S, E> {

    protected Logger logger = LoggerFactory.getLogger(getClass());

    protected Map<String, Object> context;

    protected S current;

    protected E entity;

    public AbstractStateMachine(E entity, Map<String, Object> context) {

        this.entity = entity;

        this.current = mapState(entity.getState());

        if (current == null) {
        	logger.error("State unknow exception.State = " + entity.getState());
            throw new MyException(ErrorCode.INTERNAL_SERVER_ERROR);
        }

        this.context = context;
    }

}
